package com.xiaobai.demo;

import com.xiaobai.util.ThreadUtil;
import lombok.extern.slf4j.Slf4j;

/**
 * 线程打断
 */
@Slf4j
public class ThreadInterrupted {
    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            log.info("Thread sleep");
            ThreadUtil.sleep(5); // 线程休眠会把打断标志重置为false wait join
        });
        t1.start();
        ThreadUtil.sleep(1);
        log.debug("Thread interrupt");
        t1.interrupt();
        log.debug("Thread status is {}",t1.getState());
        //像是线程sleep、wait、join的时候打断标志会重置为false
        log.debug("Thread interrupt status is {}",t1.isInterrupted()); //Thread interrupt status is false
    }
}
